package tests.utils;

import integration.IntegrationNonAdaptive;
import misc.Function;
import misc.IntgrationFunction;

import org.junit.Test;

public class IntegrationTest {

    @Test
    public void integrationNonAdaptive() {
	IntgrationFunction tempFunction = new dataFunction();
	Function tempIntegrationFunction = new IntegaretFunction();
	double result = IntegrationNonAdaptive.calcIntegration(tempFunction,
		tempIntegrationFunction, 0, Math.PI / 2.0);
	System.out.println(result);
    }

    /**
     * Represent the integral of f(x) = cos(x) / 1 +cos^2(x)
     * 
     * F(x) = ( ln(sin(x)+ 2^0.5) - ln(2^0.5 - sin(x)) ) / 2* 2 ^ 0.5
     * 
     * @author Maxim
     * 
     */
    private static class dataFunction extends IntgrationFunction {

	/**
	 * 
	 * @return F(point)
	 */
	@Override
	public double valueAtPoint(double point) {
	    return (Math.log(Math.sin(point) + Math.sqrt(2)) - Math.log(Math
		    .sqrt(2) - Math.sin(point)))
		    / (2 * Math.sqrt(2));
	}

	/**
	 * 
	 * @return F(b) - F(a)
	 * 
	 */
	@Override
	public double integrationAtRange(double point1, double point2) {
	    return valueAtPoint(point2) - valueAtPoint(point1);
	}

    }

    /**
     * Subject 1: exrecise 1.2
     * 
     * Function: cos(x) / ( 1 + cos^2(x) )
     * 
     * @author Maxim
     * 
     */
    private static class IntegaretFunction extends Function {

	@Override
	public double valueAtPoint(double point) {
	    return Math.cos(point) / (1 + Math.pow(Math.cos(point), 2));
	}
    }

}
